<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class NewsRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
//            'title'       => 'required',
            'subject'     => 'required',
            'description' => 'required',
            'status'      => 'required|boolean',
            'category_id' => 'required|numeric',
            'source'      => 'required',
            'source_url'  => 'required',
            'copyrights'  => 'required',
            'keyword'     => 'required',
            'content'     => 'required',
        ];

//        return array();

        $data = Request::all();

        //如果是创建则添加以下验证条件
        if ($data['formType'] == 'create') {
//            $rules['upid'] = 'required|numeric';
//            $rules['code'] = 'required';
        }

        return $rules;
    }

    public function attributes()
    {
        $attributes = array(
            'title'       => '标题',
            'subject'     => '主题',
            'description' => '描述',
            'content'     => '内容',
            'status'      => '前台是否可见',
            'category_id' => '所属分类',
            'source'      => '来源',
            'source_url'  => '来源url',
            'copyrights'  => '版权',
            'keyword'     => '关键词',
//            'upid'        => 'required',
//            'code'        => 'required',
        );

        return $attributes;
    }

    public function messages()
    {
        $messages = [
            'required' => ':attribute为必填选项',
            'numeric'  => ':attribute必须为数字',
        ];

        return $messages;
    }
}
